package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminRolePermission;
import  com.ygqh.baby.mapper.AdminRolePermissionMapper;
import  com.ygqh.baby.service.AdminRolePermissionService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminRolePermissionExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminRolePermissionServiceImpl implements AdminRolePermissionService{
	
	@Autowired
	private AdminRolePermissionMapper adminRolePermissionMapper;
	
	@Override
	public List<AdminRolePermission> find() {
		AdminRolePermissionExample example = new AdminRolePermissionExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminRolePermissionMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminRolePermissionExample example = new AdminRolePermissionExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminRolePermissionMapper.countByExample(example);
	}

	@Override
	public AdminRolePermission findById(Long id) {
		return adminRolePermissionMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminRolePermission adminRolePermission) {
		return adminRolePermissionMapper.insertSelective(adminRolePermission);
	}

	@Override
	public int update(AdminRolePermission adminRolePermission) {
		return adminRolePermissionMapper.updateByPrimaryKeySelective(adminRolePermission);
	}

	@Override
	public ResultSet<AdminRolePermission> search(QueryInfo queryInfo,String q) {
		List<AdminRolePermission>  list =  adminRolePermissionMapper.selectSuper(queryInfo, q);
		int count = adminRolePermissionMapper.countSuper(q);
		ResultSet<AdminRolePermission> resultSet = new ResultSet<AdminRolePermission>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminRolePermissionExample example = new AdminRolePermissionExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminRolePermission record = new AdminRolePermission();
		record.setStatus(DataStatus.Delete.name());

		return adminRolePermissionMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminRolePermission adminRolePermission) {
		int r = 0;
		if(adminRolePermission.getId() != null) {
			r = this.update(adminRolePermission);
		}else {
			r = this.save(adminRolePermission);
		}
		return r;
	}

}

